package com.naiterui.ehp.bs.b2c.cart.controller.inner;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.b2c.cart.exception.CartExceptionCodes;
import com.naiterui.ehp.bs.b2c.cart.service.ICartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <pre>
 * 购物车相关内部接口
 * </pre>
 *
 * @author fangguanhong
 * @date 2020/5/13 下午5:08
 * @since 1.0.0
 */
@Validated
@Api(tags = SwaggerTag.INNER_API + SwaggerTag.CART)
@RequestMapping("b2c/inner/carts")
@RestController
public class InnerCartController {

    private static final Logger LOGGER = LoggerFactory.getLogger(InnerCartController.class);

    @Autowired
    private ICartService cartService;

    /**
     * 针对过期处方，患者已求药的需要在购物车清除掉
     *
     * @return
     *
     * @throws BusinessException
     */
    @ApiOperation(value = "清除购物车已过期且已求药的处方")
    @ApiImplicitParam(name = "recomId", value = "处方ID", paramType = "query", dataType = "long", required = true)
    @PostMapping("/remove/require/recom")
    public ResponseVO<Void> info(@RequestParam("recomId") Long recomId) throws BusinessException {
        LOGGER.info("清除购物车已过期且已求药的处方, recomId {}", recomId);
        cartService.removeExpireRequireRecom(recomId);
        return PublicService.returnResponseVO(CartExceptionCodes.SUCCESS);
    }
}
